/// @tags: Lagrange
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const K = 6e3 + 5, mod = 1e9 + 7;

int f[2][K], prefix[K], suffix[K], fac[K], inv[K];

inline LL qpow(LL base, int exp = mod - 2) {
  LL res = 1;
  for (; exp; exp >>= 1, base = base * base % mod)
    if (exp & 1) res = res * base % mod;
  return res;
}

inline int add(int a, int b) {
  a += b;
  return a >= mod ? a - mod : a;
}

inline int dec(int a, int b) {
  a -= b;
  return a < 0 ? a + mod : a;
}

inline int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  for (int i = 0; i <= 2 * k + 1; ++i) f[0][i] = 1;
  f[1][0] = 1;
  for (int i = 1; i <= k; ++i) {
    int *cur = f[i & 1], *pre = f[!(i & 1)];
    for (int j = 1; j <= 2 * k + 1; ++j)
      cur[j] = add(cur[j - 1], (j - 1LL) * pre[j - 1] % mod);
  }
  int *A = f[k & 1];
  prefix[0] = suffix[(k = 2 * k + 1) + 1] = 1;
  if (n <= k) return cout << A[n], 0;
  for (int i = 1; i <= k; ++i) prefix[i] = (LL)prefix[i - 1] * dec(n, i) % mod;
  for (int i = k; i; i--) suffix[i] = (LL)suffix[i + 1] * dec(n, i) % mod;
  for (int i = fac[0] = 1; i <= k; ++i) fac[i] = (LL)fac[i - 1] * i % mod;
  for (int i = inv[0] = 1; i <= k; ++i) inv[i] = qpow(fac[i]);
  for (int i = 1; i <= k; ++i) {
    ans = i & 1 ? add(ans, (LL)A[i] * prefix[i - 1] % mod * suffix[i + 1] % mod *
                               inv[i - 1] % mod * inv[k - i] % mod)
                : dec(ans, (LL)A[i] * prefix[i - 1] % mod * suffix[i + 1] % mod *
                               inv[i - 1] % mod * inv[k - i] % mod);
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("guess.in", "r", stdin);
  freopen("guess.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
